$(document).ready(function () { 
	var selections=[];
	
	$("#tianjia").click(function(){
		 if(!checkform("#form_bdtd")){
			return;
		}
		var sfwzj = $("#sfwzj1").val();
		if(sfwzj==1){
			if($("#zjlx1").val()==null || $("#zjlx1").val().trim()==""){
				errorMsg = $("#zjlx1").attr("errorMsg")==undefined?"该项为必填项":$("#zjlx1").attr("errorMsg");
				$("#zjlx1").next("span").remove();
				$("#zjlx1").after("<span class='apendhtml' style='color: red;margin-left: 5px;'>"+errorMsg+"</span>");
			}
			return ;
		}
		var params =$("#form_bdtd").serializeObject();	
		var addJson = ajaxResult("get",false,"../../mbxtglqxservlet.insert.do",params);
		if(addJson.status=="OK"){
			alertFunc("添加成功");
		}else{
			alertFunc(addJson.msg);
		}
		refreshTableAtCurPage("#userInfo");
		$("#form_bdtd")[0].reset();
		$('#exampleModal34').modal('hide');
	});

	$("#save").click(function() {
		console.log("123");
		if(!checkform("#form_bdtd2")){
			return;
		}
		console.log("1234");
		var sfwzj = $("#sfwzj2").val();
		if(sfwzj==1){
			console.log("11");
			if($("#zjlx2").val()==null || $("#zjlx2").val().trim()==""){
				console.log("112");
				errorMsg = $("#zjlx2").attr("errorMsg")==undefined?"该项为必填项":$("#zjlx2").attr("errorMsg");
				console.log("113");
				$("#zjlx2").next("span").remove();
				console.log("114");
				$("#zjlx2").after("<span class='apendhtml' style='color: red;margin-left: 5px;'>"+errorMsg+"</span>");
				console.log("115");
				return ;
			}
		}
		console.log("12567585758yyyyyyy");
		//errorMsg = $(this).attr("errorMsg")==undefined?"该项为必填项":$(this).attr("errorMsg");
	   	var params =$("#form_bdtd2").serializeObject();	
		var addJson = ajaxResult("get",false,"../../mbxtglqxservlet.update.do",params);
		if(addJson.status=="OK"){
			alertFunc("更新成功");
		}else{
			alertFunc(addJson.msg);
		}
		refreshTableAtCurPage("#userInfo");
		$("#form_bdtd")[0].reset();
		$('#exampleModal2').modal('hide');
	});

	createTable('#userInfo','../../mbxtglqxServlet.getJsList.do','zdbh',tblColTitle,null,null);

	/* $table.on('check.bs.table check-all.bs.table ' +
		      'uncheck.bs.table uncheck-all.bs.table', function (e, rows) {
		      var ids = $.map(!$.isArray(rows) ? [rows] : rows, function (row) {
		        return row.qxbm
		      })
		      var func = $.inArray(e.type, ['check', 'check-all']) > -1 ? 'union' : 'difference'
		      selections = window._[func](selections, ids)
		    })*/
});

$("#query_btn").click(function(){
	refreshTable("#userInfo","#form_bd");
});
function refreshTable(tableid,formid){	 
	var params =$(formid).serializeObject();		  
	params["pageNumber"] = 1;
	params["limit"] = pageSize;
	params["offset"] = 0;	 
	$(tableid).bootstrapTable('refresh',{query:params});	
};
function selectJs(zdbh){
	$('#jsdb').bootstrapTable('destroy');
	queryTableNoPage('#jsdb','../../mbxtglqxservlet.getQx.do',jsColTitle,{zdbh:zdbh});
}

function getqx(zdbh){
	$("#ID").val(zdbh);
	var setting = {
		check: {
			enable: true
		},
		view: {
			showLine: false,
			showIcon: showIconForTree,
		},
		data: {
			simpleData: {
				enable: true
			}
		},
		callback: {
		//	onClick: zTreeOnCheck
			onCheck:onCheck
		}
	};
	$("#TreeDoc").html = '';
	var jsonTreeG = ajaxResult("get",false,"../../mbxtglqxservlet.getQxTree.do",{zdbh:zdbh});	
	if(jsonTreeG.status=='OK'){
		$.fn.zTree.init($("#TreeDoc"), setting, jsonTreeG.rows);
		$("#TreeDoc>li>span.chk").hide();
	}else{
		alertFunc("获取权限列表失败，请关闭后重新打开！");
	}
/*	var zTree = $.fn.zTree.getZTreeObj("#TreeDoc");
	var allNodes=zTree.getNodes();
	if(allNodes.length>0){
	    for(var i=0;i<allNodes.length;i++){
	        if(allNodes[i].isParent){//找到父节点
	            allNodes[i].nocheck=true;//nocheck为true表示没有选择框
	        }
	    }
	}*/
}
function showIconForTree(treeId, treeNode) {
	return !treeNode.isParent;
};
function onCheck(e, treeId, treeNode) {
	$("#TreeDoc>li>span.chk").hide();
}
var tblColTitle = [ 
	{ title: '序号', width: 50, align: "center", formatter: function (value, row, index) { return index + 1; } },
	{ title: '角色名称', field: 'jsmc' ,width: 70},
	{ title: '是否为专家', field: 'sfwzj' ,width: 50, formatter: function (value, row, index) { 
		var result=""; 
		if(row.sfwzj==1){
			result="是"
		}else{
			result="否";
		} 
		return result; 
	}},
	{ title: '专家类型', field: 'zjlx' ,width: 50},
	{ title: '角色描述', field: 'jsms' ,width: 120},
	{ title: '操作', field: '' ,width: 95,formatter: function (value, row, index) {
		var result=""; 
		if(row.sfwzj==1){
			result ="<a href='#'  onclick='selectJs("+JSON.stringify(row.zdbh)+")' data-toggle='modal' data-target='#exampleModal5'>查看</a>&nbsp;&nbsp;&nbsp;"+
			"<a href='#' onclick='getqx("+JSON.stringify(row.zdbh)+")'  data-toggle='modal' data-target='#exampleModal'>授权</a>&nbsp;&nbsp;&nbsp;";
		}
		result += "<a href='#' onclick='xiugai("+JSON.stringify(row.zdbh)+")'  data-toggle='modal' data-target='#exampleModal2'>修改</a>";
		return result; 
	}},
	
];


function queren(){
	var qxbms = [];
	var treeObj=$.fn.zTree.getZTreeObj("TreeDoc"),
    	nodes=treeObj.getCheckedNodes(true),
    v="";
	for(var i=0;i<nodes.length;i++){
   		if(nodes[i].level!=0){
	   		qxbms.push(nodes[i].id);
   		}
   	}
	var ids = new Array();
	bool=$.isArray(qxbms);
	if(bool){
		$.each(qxbms,function(index,value){			 
			ids.push(value);		
		});
	}else{
		return;
	}
	var json = ajaxResult("get",false,"../../mbxtglqxservlet.assignQx.do",{qxbms:ids.join(","),jsbm:$("#ID").val()});
	if(json.status=="OK"){
		alertFunc("分配成功");
		refreshTableAtCurPage("#userInfo");
		selections=[];
		$('#exampleModal').modal('hide');
	}else{
		alertFunc("分配失败");
		selections=[];
		refreshTableAtCurPage("#userInfo");
		$('#exampleModal').modal('hide');
	}
}

function sfwzjchange(flagval){
	if(flagval==1){
		var sfwzj = $("#sfwzj1").val();
		if(sfwzj==1){
			$("#zjlxdiv1").show();
		}else{
			$("#zjlxdiv1").hide();
		}
	}else{
		var sfwzj = $("#sfwzj2").val();
		if(sfwzj==1){
			$("#zjlxdiv2").show();
		}else{
			$("#zjlxdiv2").hide();
		}
	}
}


function xiugai(zdbh){
	 var json = ajaxResult("get",false,"../../mbxtglqxServlet.getDataById.do",{zdbh:zdbh});
	 loadDataInFrom("#form_bdtd2",json.rows);
	 var zjflag = json.rows.sfwzj;
	if(zjflag==1){
		$("#zjlxdiv2").show();
	}

}

function loadDataInFrom(formID,jsonStr){
	var obj =jsonStr;
	var key,value,tagName,type,arr;
	for(x in obj){
		key = x;
		value = obj[x];		
		
		if(key=="yhmm"){
			
		}else{
		//$(formID+" [name='"+key+"'],"+formID+" [name='"+key+"[]']").each(function(){
		$(formID+" [name='"+key+"'],"+formID+" [name='"+key+"[]']").each(function(){
			tagName = $(this)[0].tagName;
			type = $(this).attr('type');
			if(tagName=='INPUT'){
				if(type=='radio'){
					$(this).prop('checked',$(this).val()==value);
				}else if(type=='checkbox'){
					if((value+"").indexOf(',')>-1){
						arr = value.split(',');
					}else{
						arr = value;
					}
					for(var i =0;i<arr.length;i++){
						if($(this).val()==arr[i]){
							$(this).prop('checked',true);
							break;
						}
					}
				}else{
					$(this).val(value);
				}
			}else if(tagName=='SELECT' || tagName=='TEXTAREA'){
				$(this).val(value);
			}else if(tagName=='LABEL'){
				$(this).text(value);
			}else{
				$(this).val(value);
			}			
		});
		
		}
	}
	
	
}

var qxColTitle = [ 
	 {	 field: 'xzzt',
		 width: 50,
		 title: '选择',
		 class:'bs-checkbox',
		 checkbox : true 
	   },
	{ title: '权限菜单', field: 'qxms' },
	//{ title: '权限状态', field: 'qxzt' },
	{ title: '权限名称', field: 'qxmc' }
	
];
var jsColTitle = [ 
	{ title: '权限菜单', field: 'qxms' },
	//{ title: '权限状态', field: 'qxzt' },
	{ title: '权限名称', field: 'qxmc' }
];


var json = {
	rows: [
	{
	name: "代表人物",
	pId: 0,
	id: "代表人物"
	},
	{
	name: "形制信息",
	pId: 0,
	id: "形制信息"
	},
	{
	name: "文化事项",
	pId: 0,
	id: "文化事项"
	},
	{
	name: "文化人类学信息",
	pId: 0,
	id: "文化人类学信息"
	},
	{
	name: "音响信息",
	pId: 0,
	id: "音响信息"
	},
	{
	name: "馆藏信息",
	pId: 0,
	id: "馆藏信息"
	},
	{
	qxbm: "organization",
	name: "保存机构",
	pId: "馆藏信息",
	id: 2
	},
	{
	qxbm: "holding_code",
	name: "馆藏编码",
	pId: "馆藏信息",
	id: 3
	},
	{
	qxbm: "title",
	name: "乐器名称",
	pId: "馆藏信息",
	id: 4
	},
	{
	qxbm: "title_self",
	name: "自称",
	pId: "馆藏信息",
	id: 5
	},
	{
	qxbm: "phoneticsymbol",
	name: "音标",
	pId: "馆藏信息",
	id: 6
	},
	{
	qxbm: "titledescription",
	name: "名称解说词",
	pId: "馆藏信息",
	id: 7
	},
	{
	qxbm: "class_huosa",
	name: "霍萨分类",
	pId: "馆藏信息",
	id: 8
	},
	{
	qxbm: "class_bayin",
	name: "八音分类",
	pId: "馆藏信息",
	id: 9
	},
	{
	qxbm: "class_minjian",
	name: "民间分类",
	pId: "馆藏信息",
	id: 10
	},
	{
	qxbm: "class_new",
	name: "新分类",
	pId: "馆藏信息",
	id: 11
	},
	{
	qxbm: "unearthedPlace",
	name: "出土地点",
	pId: "馆藏信息",
	id: 12
	},
	{
	qxbm: "year",
	name: "年代",
	pId: "馆藏信息",
	id: 13
	},
	{
	qxbm: "birthprocess",
	name: "传世过程",
	pId: "馆藏信息",
	id: 14
	},
	{
	qxbm: "language",
	name: "语源",
	pId: "馆藏信息",
	id: 15
	},
	{
	qxbm: "usenation",
	name: "使用种族",
	pId: "馆藏信息",
	id: 16
	},
	{
	qxbm: "othernation",
	name: "其他种族",
	pId: "馆藏信息",
	id: 17
	},
	{
	qxbm: "volume",
	name: "体量",
	pId: "形制信息",
	id: 18
	},
	{
	qxbm: "formDrawing",
	name: "形制绘图",
	pId: "形制信息",
	id: 19
	},
	{
	qxbm: "formDescription",
	name: "形制说明",
	pId: "形制信息",
	id: 20
	},
	{
	qxbm: "material",
	name: "材质构成",
	pId: "形制信息",
	id: 21
	},
	{
	qxbm: "technology",
	name: "工艺传承",
	pId: "形制信息",
	id: 22
	},
	{
	qxbm: "improveState",
	name: "改良状态说明",
	pId: "形制信息",
	id: 23
	},
	{
	qxbm: "improveStateImage",
	name: "改良状态图示",
	pId: "形制信息",
	id: 24
	},
	{
	qxbm: "originDescription",
	name: "起源说明",
	pId: "文化人类学信息",
	id: 25
	},
	{
	qxbm: "originImage",
	name: "起源图示",
	pId: "文化人类学信息",
	id: 26
	},
	{
	qxbm: "originAudio",
	name: "起源音频",
	pId: "文化人类学信息",
	id: 27
	},
	{
	qxbm: "originVideo",
	name: "起源视频",
	pId: "文化人类学信息",
	id: 28
	},
	{
	qxbm: "historyDescription",
	name: "历史沿革说明",
	pId: "文化人类学信息",
	id: 29
	},
	{
	qxbm: "historyImage",
	name: "历史沿革图示",
	pId: "文化人类学信息",
	id: 30
	},
	{
	qxbm: "historyAudio",
	name: "历史沿革音频",
	pId: "文化人类学信息",
	id: 31
	},
	{
	qxbm: "historyVideo",
	name: "历史沿革视频",
	pId: "文化人类学信息",
	id: 32
	},
	{
	qxbm: "folkloreDescription",
	name: "民间传说描述",
	pId: "文化人类学信息",
	id: 33
	},
	{
	qxbm: "folkloreImage",
	name: "民间传说图像",
	pId: "文化人类学信息",
	id: 34
	},
	{
	qxbm: "folkloreAudio",
	name: "民间传说音频",
	pId: "文化人类学信息",
	id: 35
	},
	{
	qxbm: "folkloreVideo",
	name: "民间传说视频",
	pId: "文化人类学信息",
	id: 36
	},
	{
	qxbm: "faithDescription",
	name: "宗教信仰",
	pId: "文化人类学信息",
	id: 37
	},
	{
	qxbm: "faithImage",
	name: "宗教信仰图像",
	pId: "文化人类学信息",
	id: 38
	},
	{
	qxbm: "faithAudio",
	name: "宗教信仰音频",
	pId: "文化人类学信息",
	id: 39
	},
	{
	qxbm: "faithVideo",
	name: "宗教信仰视频",
	pId: "文化人类学信息",
	id: 40
	},
	{
	qxbm: "collectionPlace",
	name: "藏品收藏地",
	pId: "文化人类学信息",
	id: 41
	},
	{
	qxbm: "treasuresDescription",
	name: "珍品描述",
	pId: "文化人类学信息",
	id: 42
	},
	{
	qxbm: "pitch",
	name: "基音说明",
	pId: "音响信息",
	id: 43
	},
	{
	qxbm: "pitchAudio",
	name: "基音音频",
	pId: "音响信息",
	id: 44
	},
	{
	qxbm: "tone",
	name: "音列说明",
	pId: "音响信息",
	id: 45
	},
	{
	qxbm: "toneAudio",
	name: "音列音频",
	pId: "音响信息",
	id: 46
	},
	{
	qxbm: "temperament",
	name: "乐律说明",
	pId: "音响信息",
	id: 47
	},
	{
	qxbm: "temperamentAudio",
	name: "乐律音频",
	pId: "音响信息",
	id: 48
	},
	{
	qxbm: "range",
	name: "音域说明",
	pId: "音响信息",
	id: 49
	},
	{
	qxbm: "rangeAudio",
	name: "音域音频",
	pId: "音响信息",
	id: 50
	},
	{
	qxbm: "bestRegister",
	name: "最佳音区说明",
	pId: "音响信息",
	id: 51
	},
	{
	qxbm: "bestRegisterAudio",
	name: "最佳音区音频",
	pId: "音响信息",
	id: 52
	},
	{
	qxbm: "toneMethod",
	name: "调音法说明",
	pId: "音响信息",
	id: 53
	},
	{
	qxbm: "toneMethodAudio",
	name: "调音法视频",
	pId: "音响信息",
	id: 54
	},
	{
	qxbm: "voiceMechanism",
	name: "发音机制描述",
	pId: "音响信息",
	id: 55
	},
	{
	qxbm: "voiceMechanismVideo",
	name: "发音机制视频",
	pId: "音响信息",
	id: 56
	},
	{
	qxbm: "ousticMechanism",
	name: "数据截点为声源发声机制",
	pId: "音响信息",
	id: 57
	},
	{
	qxbm: "provoke",
	name: "声源原始激起说明",
	pId: "音响信息",
	id: 58
	},
	{
	qxbm: "provokeVideo",
	name: "声源原始激起视频",
	pId: "音响信息",
	id: 59
	},
	{
	qxbm: "struct",
	name: "声源结构说明",
	pId: "音响信息",
	id: 60
	},
	{
	qxbm: "structImage",
	name: "声源结构图示",
	pId: "音响信息",
	id: 61
	},
	{
	qxbm: "structVideo",
	name: "声源结构视频",
	pId: "音响信息",
	id: 62
	},
	{
	qxbm: "soundMaterial",
	name: "声源材质",
	pId: "音响信息",
	id: 63
	},
	{
	qxbm: "mediatorMaterial",
	name: "中介物材质说明",
	pId: "音响信息",
	id: 64
	},
	{
	qxbm: "mediatorMaterialImage",
	name: "中介物材质图示",
	pId: "音响信息",
	id: 65
	},
	{
	qxbm: "mediatorStruct",
	name: "中介物结构说明",
	pId: "音响信息",
	id: 66
	},
	{
	qxbm: "mediatorStructImage",
	name: "中介物结构图示",
	pId: "音响信息",
	id: 67
	},
	{
	qxbm: "mediatorShape",
	name: "中介物形制说明",
	pId: "音响信息",
	id: 68
	},
	{
	qxbm: "mediatorShapeAudio",
	name: "中介物形制音频",
	pId: "音响信息",
	id: 69
	},
	{
	qxbm: "VibrationTransferMaterial",
	name: "传震物材质说明",
	pId: "音响信息",
	id: 70
	},
	{
	qxbm: "VibrationTransferMaterialImage",
	name: "传震物材质图示",
	pId: "音响信息",
	id: 71
	},
	{
	qxbm: "VibrationTransferStruct",
	name: "传震物结构说明",
	pId: "音响信息",
	id: 72
	},
	{
	qxbm: "VibrationTransferStructImage",
	name: "传震物结构图示",
	pId: "音响信息",
	id: 73
	},
	{
	qxbm: "ResonatorMaterial",
	name: "共鸣器材质说明",
	pId: "音响信息",
	id: 74
	},
	{
	qxbm: "ResonatorMaterialImage",
	name: "共鸣器材质图示",
	pId: "音响信息",
	id: 75
	},
	{
	qxbm: "ResonatorStrut",
	name: "共鸣器结构说明",
	pId: "音响信息",
	id: 76
	},
	{
	qxbm: "ResonatorStrutImage",
	name: "共鸣器结构图示",
	pId: "音响信息",
	id: 77
	},
	{
	qxbm: "MainPartSound",
	name: "主要结构部位音质说明",
	pId: "音响信息",
	id: 78
	},
	{
	qxbm: "MainPartSoundAudio",
	name: "主要结构部位音质音频",
	pId: "音响信息",
	id: 79
	},
	{
	qxbm: "techniques",
	name: "主要演奏技法音质说明",
	pId: "音响信息",
	id: 80
	},
	{
	qxbm: "techniquesVideo",
	name: "主要演奏技法音质视频",
	pId: "音响信息",
	id: 81
	},
	{
	qxbm: "spectrum",
	name: "主要演奏技法音质图表及频谱说明",
	pId: "音响信息",
	id: 82
	},
	{
	qxbm: "spectrumImage",
	name: "主要演奏技法音质图表及频谱图示",
	pId: "音响信息",
	id: 83
	},
	{
	qxbm: "SpectrumAnalysis",
	name: "频谱分析说明",
	pId: "音响信息",
	id: 84
	},
	{
	qxbm: "SpectrumAnalysisImage",
	name: "频谱分析说明图示",
	pId: "音响信息",
	id: 85
	},
	{
	qxbm: "instrumentType",
	name: "乐器种类",
	pId: "文化事项",
	id: 86
	},
	{
	qxbm: "songster",
	name: "作曲者",
	pId: "文化事项",
	id: 87
	},
	{
	qxbm: "lyricist",
	name: "作词者",
	pId: "文化事项",
	id: 88
	},
	{
	qxbm: "performingForms",
	name: "演奏形式",
	pId: "文化事项",
	id: 89
	},
	{
	qxbm: "playForm",
	name: "演奏形态",
	pId: "文化事项",
	id: 90
	},
	{
	qxbm: "performer",
	name: "表演者",
	pId: "文化事项",
	id: 91
	},
	{
	qxbm: "genre",
	name: "流派",
	pId: "文化事项",
	id: 92
	},
	{
	qxbm: "toPlayClub",
	name: "演奏社团",
	pId: "文化事项",
	id: 93
	},
	{
	qxbm: "musicScoreExplain",
	name: "谱例资料说明",
	pId: "文化事项",
	id: 94
	},
	{
	qxbm: "musicScoreImage",
	name: "谱例资料图片 ",
	pId: "文化事项",
	id: 95
	},
	{
	qxbm: "inheritTeachExplain",
	name: "传承教学说明",
	pId: "文化事项",
	id: 96
	},
	{
	qxbm: "inheritTeachVideo",
	name: "传承教学视频",
	pId: "文化事项",
	id: 97
	},
	{
	qxbm: "symbolsAndTaboos",
	name: "象征与禁忌",
	pId: "文化事项",
	id: 98
	},
	{
	qxbm: "socialFunction",
	name: "社会功能",
	pId: "文化事项",
	id: 99
	},
	{
	qxbm: "culturalRole",
	name: "文化角色",
	pId: "文化事项",
	id: 100
	},
	{
	qxbm: "culturalFunction",
	name: "文化功能",
	pId: "文化事项",
	id: 101
	},
	{
	qxbm: "culturalContext",
	name: "文化语境",
	pId: "文化事项",
	id: 102
	},
	{
	qxbm: "name",
	name: "人物名称",
	pId: "代表人物",
	id: 103
	},
	{
	qxbm: "dbrwYear",
	name: "年代",
	pId: "代表人物",
	id: 104
	},
	{
	qxbm: "contribution",
	name: "贡献",
	pId: "代表人物",
	id: 105
	},
	{
	qxbm: "representativeworks",
	name: "代表著作",
	pId: "代表人物",
	id: 106
	}
	],
	status: "OK"
	}


